package com.xb.controller;

import com.xb.entity.Dept;
import com.xb.service.DeptService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/dept/*")
public class DeptController extends BaseController{

    private DeptService deptService=new DeptService();


    /**
     * 查询部门信息
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void findAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Dept> deptList=deptService.findAll();
        req.setAttribute("deptList",deptList);
        writerObjToString(resp,deptList);
    }


        /**
         * 查询部门信息包括部门id、部门名称、部门人数
         * @param req
         * @param resp
         * @throws ServletException
         * @throws IOException
         */
    protected void findDeptAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

         List<Map<String,Object>> deptMapList= deptService.findDeptAll();
         req.setAttribute("deptMapList",deptMapList);
         req.getRequestDispatcher("/html/department.jsp").forward(req,resp);
    }
}
